//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
// 			VisualNovelToolkit		     /_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe.	/_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;

public static class ViNoStringExtensions {
	
	// if str is "true" or "yes" or "TRUE" or "YES" , return true, else return false.
    public static bool  IsTrueOrYes ( string str  ){
		string exp = str.ToLower();
		return ( "true".Equals( exp ) || "yes".Equals( exp ) );			
    }
		
	// Parse Comma-delimited Vector2... "0.5 , 10 " .
    public static Vector2 ParseVector2 ( string pos  ){
       //Takes strings formatted with numbers and no spaces before or after the commas:
        // "1.0f,1.0f,.35,1.0f"
       string[] strings= pos.Split(","[0] );
       Vector2 output;
       output.x = System.Single.Parse(strings[0]);
       output.y = System.Single.Parse(strings[1]);
       return output;
    }    
    
	// Parse Comma-delimited Vector3... "0.5 , 10 , -1.0" .
    public static Vector3 ParseVector3 ( string pos  ){
       //Takes strings formatted with numbers and no spaces before or after the commas:
        // "1.0f,1.0f,.35,1.0f"
       string[] strings= pos.Split(","[0] );
       Vector3 output;
       output.x = System.Single.Parse(strings[0]);
       output.y = System.Single.Parse(strings[1]);
       output.z = System.Single.Parse(strings[2]);
       return output;
    }    
 
	// Parse Following format. 0,1,0,0 .
	static public List<int> ParseIntArray( string str ){
		List<int> ret = new List<int>();
		str = str.Replace( "\n" , "" ).Replace( "\r" , "" ).Replace( "\t" , "" );		
		string[] ids = str.Split( ","[0] );
		for(int i=0;i<ids.Length;i++){
			int id = int.Parse( ids[ i ]	 );
			ret.Add( id );
		}
		return ret;
	}
	
	static public string[] SeparatedByTwoBr( string str ){
		string text =  str.Replace( "\r" , "" );
		string[] delimiter = { "\n\n" };
		
		string[] strBlocks = text.Split( delimiter , System.StringSplitOptions.None );
		for( int i=0;i<strBlocks.Length;i++){
			ViNoDebugger.Log( "StrBlock " + i + " " + strBlocks[ i ]  );	
		}
		return strBlocks;
	}

	static public string GetDateTimeNowString(){
#if false
//		DateTime nowTime = DateTime.Now;
		System.Text.StringBuilder sb = new System.Text.StringBuilder();		 
		sb.Append( nowTime.Year.ToString() + "/" );
		sb.Append( nowTime.Month.ToString() + "/" );
		sb.Append( nowTime.Day.ToString() + "/" );
		sb.Append( nowTime.Hour.ToString() + ":" );	
		sb.Append( nowTime.Minute.ToString () + ":" );
		sb.Append( nowTime.Second.ToString( ) );
		return sb.ToString();		
#else
		return DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
#endif		
	}	
}

